//
//  ViewController.m
//  06-了解-corelocation框架的基本使用—区域监听
//
//  Created by J on 16/2/27.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface ViewController ()<CLLocationManagerDelegate>
@property(nonatomic,strong)CLLocationManager* manager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    CLLocationManager* manager = [CLLocationManager new];
    self.manager = manager;
    manager.delegate = self;
    
    if ([self.manager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        [manager requestAlwaysAuthorization];

    }
    [self.manager requestWhenInUseAuthorization];
    


    
    
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(51.50998, -0.1337);
    CLCircularRegion* region = [[CLCircularRegion alloc] initWithCenter:center radius:1000 identifier:@"小码哥"];
    [self.manager startMonitoringForRegion:region];
//    [self.manager requestStateForRegion:region];//会自动调用进入和出去
}



- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region{
    NSLog(@"离开区域");
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{
    NSLog(@"进入区域");
}


- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{
    
    NSLog(@"%zd",state);
    
}


@end
